package com.ldodds.ot;

import com.ldodds.ot.id.IdentifierRewriter;

/**
 * Default implementation of the Item interface
 * 
 * Instances of this class can be configured to use a specific instance of the 
 * IdentifierRewriter interface to handle the mapping between its primary 
 * and web identifiers. If no implementation is provided then it is assumed that 
 * the two identifiers are identical. 
 * 
 * @author Leigh Dodds
 * @see Identifiable
 */
public class ItemImpl extends PropertyHolderImpl implements Item {

	private String identifier;
	private IdentifierRewriter rewriter;
	
	public ItemImpl(String identifier) {
		this(identifier, null );
	}

	public ItemImpl(String identifier, IdentifierRewriter rewriter) {
		this.identifier = identifier;		
		this.rewriter = rewriter;
	}
	
	public String getIdentifier() {
		return identifier;
	}

	public String getWebIdentifier() {
		if (rewriter != null) {
			return rewriter.getWebIdentifier( identifier );
		}
		return identifier;
	}

}
